<?php 
	class ControllerMemoryPrivatesetting extends Controller {
		private $error = array();
		public function index() {
			$this->document->setTitle("privatesetting");
			$data['maincontent'] = "个人设置";
			$this->load->model("user/user");
			$nickname = $this->model_user_user->getNicknameByUserid($this->session->data['user_id']);
			$data['nickname'] = !empty($nickname) ? $nickname : $this->session->data['username'];
			$data['editnicknameurl'] = $this->url->link('memory/privatesetting/editNickname','',true)."&token=".$this->session->data['token'];
			$data['oldpasswordvelurl'] = $this->url->link('memory/privatesetting/oldPasswordVel','',true)."&token=".$this->session->data['token'];
			$data['resetpasswordurl'] = $this->url->link('memory/privatesetting/resetPassword','',true)."&token=".$this->session->data['token'];
			$data['header'] = $this->load->controller('common/headerin');
	 		$data['footerin'] = $this->load->controller('common/footerin');
	 		$data['footer'] = $this->load->controller('common/footer');
	 		$this->response->setOutput($this->load->view('memory/privatesetting', $data));
		}
		public function editNickname(){
            if($this->request->server['REQUEST_METHOD'] == 'POST') {
                $this->load->model('user/user');
                $nickname = $this->request->post['nickname'];
                if($this->model_user_user->editNickname($nickname,$this->session->data['user_id'])){
					$info = "昵称修改成功";
				};
                header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($info,0));
            }
        }
        public function oldPasswordVel(){
            if($this->request->server['REQUEST_METHOD'] == 'POST') {
                $oldpassword = $this->request->post['oldpassword'];
                $username = $this->session->data['username'];
                 $bool = $this->user->login($username,$oldpassword);
                 if($bool === "2") {
                 	$bool = false;
                 }
                header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($bool,0));
            }
        }
        public function resetPassword(){
            if($this->request->server['REQUEST_METHOD'] == 'POST') {
                $this->load->model('user/user');
                $num;
                $password = $this->request->post['password'];
                $userid = $this->session->data['user_id'];
	 		if ($this->model_user_user->resetPassword($userid,$password)) {
	 			$num = 1;
	 		} else {
	 			$num = 0;
	 		}
            header('Content-Type:application/json; charset=utf-8');
            exit(json_encode($num,0));
            }
        }
	}
 ?>